import BasicController from './../BasicController'
import ErrorHandlerCode from './../../util/ErrorHandlerCode'
import {ExcellentModel} from './../../model'

class ExcellentController extends BasicController{
	insert(req,res){
		if(!super.isEmptyParameter(req.body.name)){
    		res.json({
                code:ErrorHandlerCode.MISSINGPARAMETER,
                message: 'name 为必填参数'
            })
            return;
    	}
    	if(!super.isEmptyParameter(req.body.field)){
    		res.json({
                code:ErrorHandlerCode.MISSINGPARAMETER,
                message: 'field 为必填参数'
            })
            return;
    	}
    	if(!super.isEmptyParameter(req.body.gradu_goto)){
    		res.json({
                code:ErrorHandlerCode.MISSINGPARAMETER,
                message: 'gradu_goto 为必填参数'
            })
            return;
    	}
    	if(!super.isEmptyParameter(req.body.is_publish)){
    		res.json({
                code:ErrorHandlerCode.MISSINGPARAMETER,
                message: 'is_publish 为必填参数'
            })
            return;
    	}
    	ExcellentModel.insert(req.body).then((data) =>{
            super.RequestSuccessMsg(res, data);
        }).catch((err) => {
            res.json(ErrorHandlerCode.INNERSERVICERROR);
            throw err;
        })
	}
	delExcellent(req,res){
		if(!super.isEmptyParameter(req.body.id)){
    		res.json({
                code:ErrorHandlerCode.MISSINGPARAMETER,
                message: 'id 为必填参数'
            })
            return;
    	}
    	ExcellentModel.deleteById(req.body.id).then((data) =>{
            super.RequestSuccessMsg(res, data);
        }).catch((err) => {
            res.json(ErrorHandlerCode.INNERSERVICERROR);
            throw err;
        })
	}
	listpageExcellent(req,res){
		if(!super.isEmptyParameter(req.body.page_size)){
    		req.body.page_size = 10;
    	}
    	if(!super.isEmptyParameter(req.body.page_no)){
    		req.body.page_no = 1;
    	}
    	ExcellentModel.findByPage(req.body).then((data) =>{
            super.RequestSuccessMsg(res, data);
        }).catch((err) => {
            res.json(ErrorHandlerCode.INNERSERVICERROR);
            throw err;
        })
	}
	updateExcellent(req,res){
		if(!super.isEmptyParameter(req.body.id)){
    		res.json({
                code:ErrorHandlerCode.MISSINGPARAMETER,
                message: 'id 为必填参数'
            });
            return;
    	}
		ExcellentModel.update(req.body).then((data) =>{
            super.RequestSuccessMsg(res, data);
        }).catch((err) => {
            res.json(ErrorHandlerCode.INNERSERVICERROR);
            throw err;
        })
	}
    findPublishList(req,res){
        if(!super.isEmptyParameter(req.body.is_publish)){
            res.json({
                code:ErrorHandlerCode.MISSINGPARAMETER,
                message: 'is_publish 为必填参数'
            });
            return;
        }
        ExcellentModel.findListPublish().then((data) =>{
            super.RequestSuccessMsg(res, data);
        }).catch((err) => {
            res.json(ErrorHandlerCode.INNERSERVICERROR);
            throw err;
        })
    }
}

module.exports = new ExcellentController();